//
//  HMTabBar.m
//  微博app--OC
//
//  Created by xmy on 16/8/30.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "HMTabBar.h"

@interface HMTabBar ()
@property(nonatomic,weak)UIButton *addbtn;
@end
@implementation HMTabBar

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.addbtn.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.5);
    
    //设置宽
    CGFloat viewW = self.frame.size.width / 5;
    
    int index = 0;
    
    for (UIView *btn in self.subviews) {
        if([btn isKindOfClass:NSClassFromString(@"UITabBarButton")]){
            
//            btn.frame.origin.x = index *viewW;
            
            
            btn.frame = CGRectMake(index *viewW , 0, viewW, self.bounds.size.height);
            
            index += 1;
            
            if(index == 2){
                index += 1;
            }
        }
    }


}

-(UIButton *)addbtn{
    if(_addbtn == nil){
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [ btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];
        
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateSelected];
        
         [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        
        _addbtn = btn;
        [btn sizeToFit];
        
        [self addSubview:_addbtn];

        
    }
    return _addbtn;
}

- (void)btnClick{
    
    if(self.tabar != nil){
        self.tabar = ^{
            
        };
    }
    
}
@end
